#include "homepage.h"
#include "ui_homepage.h"
#include <QDebug>
#include <QPainter>
#include <QPen>

HomePage::HomePage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HomePage)
{
    ui->setupUi(this);
    this->setLayout(ui->gridLayout);
    eliminationPushButtonBorder();

    //设置自定义的鼠标指针图案
    QCursor *myCursor= new QCursor(QPixmap(":/Mouse/Image/mouse/mouse.png"),15,10);
    setCursor(*myCursor);
}

HomePage::~HomePage()
{
    delete ui;
}

void HomePage::on_pushButton_Stock_clicked()
{
    emit PushButtonResponse(tr("stockpage"));
}

void HomePage::on_pushButton_Purchase_clicked()
{
    emit PushButtonResponse(tr("purchasepage"));
}

void HomePage::eliminationPushButtonBorder()
{
    //消除边框
    ui->pushButton_Commodity_Sales->setFlat(true);
    ui->pushButton_Purchase->setFlat(true);
    ui->pushButton_Sales_Detail->setFlat(true);
    ui->pushButton_Stock->setFlat(true);
    ui->pushButton_Stock_Adjustment->setFlat(true);
    ui->pushButton_Stock_Counts->setFlat(true);
}

void HomePage::resizeEvent(QResizeEvent *)
{
    this->setAutoFillBackground(true);
//    QPixmap pixmap(":/homepage/Image/homePage/background/ShowerPhotos.jpg");
//    QPixmap pixmap(":/homepage/Image/homePage/background/LinYunEr.jpg");
//    QPixmap pixmap(":/homepage/Image/homePage/background/grassland.jpg");
    QPixmap pixmap(":/homepage/Image/homePage/background/flower.jpg");
//    QPixmap pixmap(":/homepage/Image/homePage/background/gril.jpg");
    QPalette palette;
    palette.setBrush(QPalette::Window, QBrush(pixmap.scaled(size(),
                    Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
    setPalette(palette);
}

//画连接线　可根据窗口大小合理调节
void HomePage::paintEvent(QPaintEvent *)
{
    //声明绘图工具
    QPainter painter(this);

    //消锯齿
    painter.setRenderHint(QPainter::Antialiasing);

    //绘制小时刻度线
    QPen thickPen(Qt::yellow, 5);//设置刻度线为粗黑
    painter.setPen(thickPen);
    painter.drawLine(ui->pushButton_Stock->x() + 50,
                     ui->pushButton_Stock->y() + 48,
                     ui->pushButton_Purchase->x() + 50,
                     ui->pushButton_Purchase->y() + 48);
    painter.drawLine(ui->pushButton_Stock->x() + 50,
                     ui->pushButton_Stock->y() + 48,
                     ui->pushButton_Commodity_Sales->x() + 50,
                     ui->pushButton_Commodity_Sales->y() + 48);
    painter.drawLine(ui->pushButton_Stock->x() + 50,
                     ui->pushButton_Stock->y() + 48,
                     ui->pushButton_Sales_Detail->x() + 50,
                     ui->pushButton_Sales_Detail->y() + 48);
    painter.drawLine(ui->pushButton_Stock->x() + 50,
                     ui->pushButton_Stock->y() + 48,
                     ui->pushButton_Stock_Adjustment->x() + 50,
                     ui->pushButton_Stock_Adjustment->y() + 48);
    painter.drawLine(ui->pushButton_Stock->x() + 50,
                     ui->pushButton_Stock->y() + 48,
                     ui->pushButton_Stock_Counts->x() + 50,
                     ui->pushButton_Stock_Counts->y() + 48);
}

void HomePage::on_pushButton_Commodity_Sales_clicked()
{
    emit PushButtonResponse(tr("commoditySalesPage"));
}
